<?php

namespace App;


class Topic extends Model
{
    protected $table = 'topics';

    protected $primaryKey = 'id';

    //专题中的文章 多对多
    public function posts()
    {
        return $this->belongsToMany(\App\Post::class, 'post_topics', 'topic_id', 'post_id');
    }

    //专题中的文章数 专题和专题文章关系表 一对多 用来withcount
    public function postTopics()
    {
        return $this->hasMany(\App\PostTopic::class,'topic_id','id');
    }
}
